﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Common;

namespace DataAccessLayer
{
    //Purpose: This class is used for Dropdowns
    public static class GenericUtility
    {
        public const string MASTERTYPES = "select master_item from master_item_types where isforratemanagement=1";

        public const string CHARGECODES = "Select Charge_Code from Charge_Code_Master where status=1";

        public const string UNITCODES = "Select Unit_Code from Unit_Code_Master where status=1 and iscustomunit=1";

        public const string DEFAULTUNITCODES = "Select Unit_Code from Unit_Code_Master where status=1 and iscustomunit=0 or iscustomunit is null";

        public static ArrayList GetDropDownData(string query)
        {
            Database objDatabase = null;
            DatabaseProviderFactory Objfactory = new DatabaseProviderFactory();

            objDatabase = Objfactory.CreateDefault();
            IDataReader IObjDataReader = objDatabase.ExecuteReader(CommandType.Text, query);
            ArrayList result = new ArrayList();
            while (IObjDataReader.Read())
            {
                result.Add(IObjDataReader[0].ToString());
            }
            return result;
       }
       
        public static List<SingleColumn> GetSingleColumnData(string query)
        {
            Database objDatabase = null;
            DatabaseProviderFactory Objfactory = new DatabaseProviderFactory();

            objDatabase = Objfactory.CreateDefault();
            IDataReader IObjDataReader = objDatabase.ExecuteReader(CommandType.Text, query);
            List<SingleColumn> result = new List<SingleColumn>();
            while (IObjDataReader.Read())
            {
                result.Add(new SingleColumn(IObjDataReader[0].ToString()));
            }
            return result;
        }

        public static ArrayList GetItemsByMasterType(string master_type)
        {
            string query = "select Master_Items from Master_Items where Master_Item=" + master_type;
            Database objDatabase = null;
            DatabaseProviderFactory Objfactory = new DatabaseProviderFactory();

            objDatabase = Objfactory.CreateDefault();
            IDataReader IObjDataReader = objDatabase.ExecuteReader(CommandType.Text, query);
            ArrayList result = new ArrayList();
            while (IObjDataReader.Read())
            {
                result.Add(IObjDataReader[0].ToString());
            }
            return result;


        }

        

      }
   
   
}
